home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-12-09 | 7.0 KB | 259 lines | [TEXT/PJMM] |
- { TransSkel multiple-window demonstration: Help module}
-
- { This module handles a help window, in which text may be scrolled but}
- { not edited. A TextEdit record is used to hold the text, though.}
-
- { 14 June 1986 Paul DuBois}
- { 7 January 1987 Ported to LightSpeed Pascal by Owen Hartnett }
- { Ωhm Software Company }
-
- unit MSkelHelp;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf,
- {$ENDC}
- MultiSkelGlobals, common, TransSkel;
-
- procedure HelpWindInit;
-
- implementation
-
- var
- teHelp: TEHandle; { handle to help window TextEdit record }
- helpScroll: ControlHandle; { help window scroll bar }
- helpLine, halfPage: integer; { line currently at top of window }
- { number of lines in half a window }
-
- procedure Halt;
-
- begin
- TEDispose(teHelp);
- DisposeControl(helpScroll);
- CloseWindow(helpWind);
- end;
-
- { Scroll to the correct position. lDelta is the}
- { amount to CHANGE the current scroll setting by.}
-
- procedure DoScroll (lDelta: integer);
-
- var
- newLine: integer;
-
- begin
- newLine := helpLine + lDelta;
- if newLine < 0 then
- newLine := 0;
- if newline > GetCtlMax(helpScroll) then
- newline := GetCtlMax(helpScroll);
- SetCtlValue(helpScroll, newLine);
- lDelta := (helpLine - newLine) * (teHelp^^.lineHeight);
- TEScroll(0, lDelta, teHelp);
- helpLine := newLine;
- end;
-
- { Filter proc for tracking mousedown in scroll bar. The part code}
- { of the part originally hit is stored as the control's reference}
- { value.}
-
- procedure TrackScroll (theScroll: ControlHandle; partCode: integer);
-
- var
- lDelta: integer;
-
- begin
- if (partCode = GetCRefCon(theScroll)) then
- begin
- case partCode of
- inUpButton:
- lDelta := -1;
- inDownButton:
- lDelta := 1;
- inPageUp:
- lDelta := -halfPage;
- inPageDown:
- lDelta := halfPage;
- otherwise
- ;
- end;
- DoScroll(lDelta);
- end;
- end;
-
- { Handle hits in scroll bar}
-
- procedure Mouse (thePt: Point; t: longint; mods: integer);
-
- var
- thePart, ignore: integer;
-
- begin
- thePart := TestControl(helpScroll, thePt);
- if thePart = inThumb then
- begin
- ignore := TrackControl(helpScroll, thePt, nil);
- DoScroll(GetCtlValue(helpScroll) - helpline);
- end
- else if thePart <> 0 then
- begin
- SetCRefCon(helpScroll, longint(thePart));
- ignore := TrackControl(helpScroll, thePt, @TrackScroll);
- end;
- end;
-
- { Update help window. The update event might be in response to a}
- { window resizing. If so, resize the rects and recalc the linestarts}
- { of the text. To resize the rects, only the right edge of the}
- { destRect need be changed (the bottom is not used, and the left and}
- { top should not be changed). The viewRect should be sized to the}
- { screen. Pull text down if necessary to fill window.}
-
- procedure update (resized: Boolean);
-
- var
- r: Rect;
- visLines, lHeight, topLines, nLines, scrollLines, ignore: integer;
-
- begin
- r := helpWind^.portRect;
- EraseRect(r);
- if resized then
- begin
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
-
- teHelp^^.destRect.right := r.right;
- teHelp^^.viewRect := r;
- TECalText(teHelp);
- lHeight := teHelp^^.lineHeight;
- nLines := teHelp^^.nLines;
- visLines := (r.bottom - r.top) div lHeight;
- halfPage := visLines div 2;
- topLines := (r.top - teHelp^^.destRect.top) div lHeight;
- scrollLines := visLines - (nLines - topLines);
- if (scrollLines > 0) and (topLines > 0) then
- begin
- if scrollLines > topLines then
- scrollLInes := topLines;
- TEScroll(0, scrollLines * lHeight, teHelp);
- end;
- scrollLines := nLines - visLines;
- helpLine := (r.top - teHelp^^.destRect.top) div lHeight;
-
- { move and resize the scroll bar as well. The ValidRect call is done}
- { because the HideControl adds the control bounds box to the update}
- { region - which would generate another update event! Since everything}
- { gets redrawn below, the ValidRect is used to cancel the update.}
-
- HideControl(helpScroll);
- r := helpWind^.portRect;
- r.left := r.right - 15;
- r.bottom := r.bottom - 14;
- r.top := r.top - 1;
- r.right := r.right + 1;
- SizeControl(helpScroll, r.right - r.left, r.bottom - r.top);
- MoveControl(helpScroll, r.left, r.top);
- if nLines - visLines < 0 then
- ignore := 0
- else
- ignore := nLines - vislines;
- SetCtlMax(helpScroll, ignore);
- SetCtlValue(helpScroll, helpLine);
- ShowControl(helpScroll);
- end;
- DrawGrowBox(helpWind);
- DrawControls(helpWind); { redraw scroll bar }
- r := teHelp^^.viewRect;
- TEUpdate(r, teHelp); { redraw text display }
- ValidRect(helpWind^.portRect);
- end;
-
- { When the window comes active, disable the Edit menu and highlight}
- { the scroll bar if there are any lines not visible in the content}
- { region. When the window is deactivated, enable the Edit menu and}
- { un-highlight the scroll bar.}
-
- procedure Activate (active: Boolean);
-
- var
- ignore: integer;
-
- begin
- DrawGrowBox(helpWind);
- if active then
- begin
- DisableItem(editMenu, 0);
- if GetCtlMax(helpScroll) > 0 then
- ignore := 0
- else
- ignore := 255;
- HiLiteControl(helpScroll, ignore);
- end
- else
- begin
- EnableItem(editMenu, 0);
- HiLiteControl(helpScroll, 255);
- end;
- DrawMenuBar;
- end;
-
- procedure HelpWindInit;
-
- var
- r: Rect;
- textHandle: Handle;
- visLines, scrollLines: integer;
-
- begin
- helpWind := GetNewWindow(helpWindRes, nil, WindowPtr(-1));
- dummy := SkelWindow(helpWind, @Mouse, nil, @Update, @Activate, nil, @Halt, nil, true);
- TextFont(0);
- TextSize(0);
-
- r := helpWind^.portRect;
- r.left := r.left + 4;
- r.bottom := r.bottom - 2;
- r.top := r.top + 2;
- r.right := r.right - 19;
- teHelp := TENew(r, r);
- textHandle := GetResource('TEXT', helpTextRes); {read help text}
- HLock(textHandle);
- TEInsert(textHandle^, GetHandleSize(textHandle), teHelp);
- HUnlock(textHandle);
- ReleaseResource(textHandle); { done with it, so goodbye }
-
- { Now figure out how many lines will fit in the window and how many}
- { will not. Determine the number of lines in half a window for use}
- { in tracking clicks in the page up and page down regions of the}
- { scroll bar. Then create the scroll bar . Make sure the borders }
- { overlap the window frame and the frame of the grow box. }
-
- visLines := (r.bottom - r.top) div teHelp^^.lineHeight;
- scrollLines := teHelp^^.nLines - visLines;
- halfPage := visLines div 2;
- helpline := 0;
- r := helpWind^.portRect;
- r.left := r.right - 15;
- r.bottom := r.bottom - 14;
- r.top := r.top - 1;
- r.right := r.right + 1;
-
- { Build the scroll bar. Don't need to bother testing whether to}
- { highlight it or not, since that will be done in response to the}
- { activate event.}
-
- helpScroll := NewControl(helpWind, r, '', true, helpLine, 0, scrollLines, scrollBarProc, 0);
-
- { GetNewWindow generates an update event for entire portRect.}
- { Cancel it, since the everything has been drawn already,}
- { except for the grow box (which will be drawn in response}
- { to the activate event).}
-
- ValidRect(helpWind^.portRect);
- end;
- end.